<template>
  <div class="detail">
    <section class="detail-block">
      <p>企业名称：{{ userInfo.tenantName }}</p>
      <p>实名认证：{{ AUTH[userInfo.isAuth] }}</p>
      <p>所属项目：{{ userInfo.appName }}</p>
      <p>统一社会信用代码：{{ userInfo.uscCode }}</p>
      <p>银行客户经理工号：{{ userInfo.managerNo }}</p>
    </section>
    <el-button class="mb20 btn" size="small" type="primary" @click="refreshData()">数据刷新</el-button>
    <nav class="common-nav mb20">
      <h2
        style="width: 120px"
        class="common-nav__title"
        :class="index === activeIndex ? 'tab_active' : ''"
        @click="switchNav(item, index)"
        v-for="(item, index) in navList"
        :key="index"
      >
        {{ item.name }}
      </h2>
    </nav>
    <main>
      <CertificationInfo
        v-show="activeIndex === 0"
        :certificationInfo="{ ...userInfo, ...companyInfo }"
      ></CertificationInfo>
      <EnterpriseInfo v-show="activeIndex === 1" :enterpriseInfo="companyInfo"></EnterpriseInfo>
      <ShareholderInfo :shareholderInfo="shareholderInfo" v-show="activeIndex === 2"></ShareholderInfo>
      <BusinessChangeInfo :businessChangeInfo="businessChangeInfo" v-show="activeIndex === 3"></BusinessChangeInfo>
      <EnterpriseLitigationInfo
        :enterpriseLitigationInfo="enterpriseLitigationInfo"
        :administrativePenalties="administrativePenalties"
        :judicialExecution="judicialExecution"
        :judicialDishonesty="judicialDishonesty"
        :taxEnforcement="taxEnforcement"
        v-show="activeIndex === 4"
      ></EnterpriseLitigationInfo>
    </main>
    <!-- 区别来源是金赋水还金茂融 -->
    <section v-if="$route.query.appCode === 'JFS'">
      <nav class="common-nav mb20">
        <h2 style="width: 136px" class="common-nav__title tab_active">全部订单</h2>
      </nav>
      <BaseSearch :config="searchConfig" v-bind="form" ref="search"></BaseSearch>
      <BaseTable :columns="columns" v-bind="table">
        <template slot="paymentStatus" slot-scope="scope">
          <span class="mr5">{{ ORDER_STATUS[scope.row.paymentStatus] }}</span>
          <el-tooltip
            v-if="scope.row.paymentStatus"
            class="item"
            effect="dark"
            :content="ORDER_STATUS[scope.row.paymentStatus]"
            placement="top"
          >
            <i class="el-icon-question"></i>
          </el-tooltip>
        </template>
      </BaseTable>
    </section>
    <!-- 金茂融 -->
    <section v-if="$route.query.appCode === 'WMR'">
      <RiskControl v-on:change-status="changeStatus" :isCredit="isCredit"></RiskControl>
    </section>
    <section v-if="$route.query.appCode.indexOf('KHY') > -1">
      <khyCreditAudit :pagetype="'1'"></khyCreditAudit>
    </section>
  </div>
</template>

<script>
import { AUTH } from '@/constants/enterpriseModel'
import CertificationInfo from '@/components/CertificationInfo/index.vue'
import EnterpriseInfo from '@/components/EnterpriseInfo/index.vue'
import ShareholderInfo from '@/components/ShareholderInfo/index.vue'
import BusinessChangeInfo from '@/components/BusinessChangeInfo/index.vue'
import EnterpriseLitigationInfo from '@/components/EnterpriseLitigationInfo/index.vue'
import BaseTable from '@/components/BaseTable/index.vue'
import BaseSearch from '@/components/BaseSearch/index.vue'
import { FormTableMixin } from '@/mixins/form-table'
import http from '@/utils/request'
import { ORDER_STATUS_LIST, ORDER_STATUS } from '@/constants/auditModel.js'
import RiskControl from '@/components/RiskControl/index.vue'
import khyCreditAudit from '@/components/RiskControl/khyCreditAudit/index.vue'
function service(params) {
  if (this.$route.query.appCode === 'JFS') {
    return http
      .get('/orders', {
        params: { ...params, queryType: 3, queryId: this.$route.query.applyId },
      })
      .then(res => {
        return {
          data: res.records,
          total: res.total,
        }
      })
  }
}

export default {
  name: 'companyDetail',
  components: {
    CertificationInfo,
    EnterpriseInfo,
    ShareholderInfo,
    BusinessChangeInfo,
    EnterpriseLitigationInfo,
    BaseTable,
    BaseSearch,
    RiskControl,
    khyCreditAudit,
  },
  mixins: [FormTableMixin(service)],
  data() {
    return {
      AUTH,
      ORDER_STATUS,
      userInfo: {},
      companyInfo: {},
      // 股东信息
      shareholderInfo: [],
      // 工商变更
      businessChangeInfo: [],
      // 企业涉诉
      enterpriseLitigationInfo: {},
      // 工商行政处罚
      administrativePenalties: [],
      // 司法执行
      judicialExecution: [],
      // 司法失信
      judicialDishonesty: [],
      // 税务执行
      taxEnforcement: [],
      activeIndex: 0,
      navList: [
        { name: '认证信息', id: 1 },
        { name: '企业信息', id: 2 },
        { name: '股东信息', id: 3 },
        { name: '工商变更', id: 4 },
        { name: '企业涉诉', id: 5 },
      ],
      searchConfig: [{ component: 'select', prop: 'paymentStatus', label: '状态', options: ORDER_STATUS_LIST }],
      columns: [
        { label: '订单日期', prop: 'createdAt' },
        { label: '订单编号', prop: 'purOrderNumber' },
        { label: '供应商', prop: 'customerName' },
        { label: '采购商', prop: 'companyName' },
        {
          label: '状态',
          prop: 'paymentStatus',
        },
        { label: '订单金额', prop: 'salesTotalAmount' },
      ],
    }
  },
  computed: {
    isCredit() {
      return this.$route.query.isFromEnterprise ? true : false
    },
  },
  methods: {
    changeStatus() {
      this.getDetailRequest()
    },
    switchNav(item, index) {
      if (this.activeIndex === index) return
      this.activeIndex = index
    },
    refreshData() {
      const flushPy = 1
      this.getDetailRequest(flushPy)
    },
    async getDetailRequest(isRefresh) {
      const {
        userInfo,
        companyInfo,
        shareholderInfo,
        saicAlterInfos,
        corpRiskInfoStat,
        saicCaseInfos,
        corpRiskInfoSummaryZXS,
        corpRiskInfoSummarySXS,
        corpRiskInfoSummarySWS,
      } = await this.$http.get(`/ents/${this.$route.query.companyId}`, {
        params: {
          flushPy: isRefresh || 0,
        },
      })
      this.userInfo = userInfo
      this.companyInfo = companyInfo
      this.shareholderInfo = shareholderInfo
      this.businessChangeInfo = saicAlterInfos
      this.enterpriseLitigationInfo = corpRiskInfoStat
      this.administrativePenalties = saicCaseInfos
      this.judicialExecution = corpRiskInfoSummaryZXS
      this.judicialDishonesty = corpRiskInfoSummarySXS
      this.taxEnforcement = corpRiskInfoSummarySWS
    },
  },
  mounted() {
    this.getDetailRequest()
  },
}
</script>

<style lang="scss" scoped>
@import './index.scss';
</style>
